package com.hx.study.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hx.common.annotation.Log;
import com.hx.common.core.controller.BaseController;
import com.hx.common.core.domain.AjaxResult;
import com.hx.common.core.page.TableDataInfo;
import com.hx.common.enums.BusinessType;
import com.hx.common.utils.poi.ExcelUtil;
import com.hx.study.domain.QuestionAnswer;
import com.hx.study.service.IQuestionAnswerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 候选答案Controller
 *
 * @author user
 * @date 2022-06-06
 */
@RestController
@RequestMapping("/exam/questionAnswer")
public class QuestionAnswerController extends BaseController {
    @Autowired
    private IQuestionAnswerService questionAnswerService;

    /**
     * 查询候选答案列表
     */
    @PreAuthorize("@ss.hasPermi('exam:questionAnswer:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuestionAnswer questionAnswer) {
        startPage();
        List<QuestionAnswer> list = questionAnswerService.selectQuestionAnswerList(questionAnswer);
        return getDataTable(list);
    }

    /**
     * 导出候选答案列表
     */
    @PreAuthorize("@ss.hasPermi('exam:questionAnswer:export')")
    @Log(title = "候选答案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionAnswer questionAnswer) {
        List<QuestionAnswer> list = questionAnswerService.selectQuestionAnswerList(questionAnswer);
        ExcelUtil<QuestionAnswer> util = new ExcelUtil<QuestionAnswer>(QuestionAnswer.class);
        util.exportExcel(response, list, "候选答案数据");
    }

    /**
     * 获取候选答案详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:questionAnswer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(questionAnswerService.selectQuestionAnswerById(id));
    }

    /**
     * 新增候选答案
     */
    @PreAuthorize("@ss.hasPermi('exam:questionAnswer:add')")
    @Log(title = "候选答案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionAnswer questionAnswer) {
        return toAjax(questionAnswerService.insertQuestionAnswer(questionAnswer));
    }

    /**
     * 修改候选答案
     */
    @PreAuthorize("@ss.hasPermi('exam:questionAnswer:edit')")
    @Log(title = "候选答案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionAnswer questionAnswer) {
        return toAjax(questionAnswerService.updateQuestionAnswer(questionAnswer));
    }

    /**
     * 删除候选答案
     */
    @PreAuthorize("@ss.hasPermi('exam:questionAnswer:remove')")
    @Log(title = "候选答案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(questionAnswerService.deleteQuestionAnswerByIds(ids));
    }
}
